﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Bovril.Rodney.Core;

namespace Bovril.Rodney.TestbedCL
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                using (IServiceClient serviceClient = ServiceClientFactory.CreateServiceClient())
                {
                    Console.WriteLine("Login successful");
                    foreach (IEvent evnt in serviceClient.EventHierarchy.RootEvents)
                    {
                        Console.WriteLine(evnt);
                        Console.WriteLine("\t{0} children", evnt.GetChildEvents().Count());
                    }

                    IEvent horseRacingEvent = serviceClient.EventHierarchy.RootEvents.First(evnt => evnt.Name == "Horse Racing");
                    IEvent gbHorseRacingEvent = horseRacingEvent.GetChildEvents().First(evnt => evnt.Name == "GB");
                    IEvent[] gbHorseRacingChildEvents = gbHorseRacingEvent.GetChildEvents();
                    foreach (IEvent gbHorseRacingChildEvent in gbHorseRacingChildEvents)
                    {
                        IMarketSummary[] marketSummaries = gbHorseRacingChildEvent.GetMarketSummaries();
                        foreach (IMarketSummary marketSummary in marketSummaries)
                            Console.WriteLine(marketSummary);
                    }
                }
            }
            catch (BetfairAPIException ex)
            {
                Console.WriteLine("Betfair API Exception: {0}", ex.ToString());
            }
        }
    }
}
